﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using imaginecup.information;
using imaginecup.objectManager;
using Imaginecup.gameState.malaria.componentInit;
using Imaginecup.util;
using Microsoft.Xna.Framework;
using Imaginecup.util.collision;
using Imaginecup.gameState.malaria.component.util;
using imaginecup.util;
using Microsoft.Xna.Framework.Input;
using Imaginecup.gameState.malaria.component.entity.effect;
using Imaginecup.gameState.malaria.component.entity.fieldItem;

namespace Imaginecup.gameState.malaria.component.entity.item
{
    /// <summary>
    /// 이것은 IUpdateable을 구현하는 게임 구성 요소입니다.
    /// </summary>
    public class CmpWebItem : BaseItemEntityComponent//, ISourceInfoClass
    {
        private List<ICmpMalaria> m_MalariaList;

        private AttackInfo m_AttackInfo;

        private bool m_bSelect;

        public CmpWebItem(GObjectID a_GID, ObjectManager objMan)
            : base(a_GID, objMan, ComponentTypeID.CID_ITEM_ENTITY)
        {
            m_MalariaList = new List<ICmpMalaria>();
            m_AttackInfo = new AttackInfo();
            m_AttackInfo.attackID = AttackID.ATTACK_MOVE;
            m_AttackInfo.extraData = m_MalariaList;

            m_bSelect = true;

            m_Info = new EntityInfo();
            m_Info.mSize = new Vector2(50, 50);

        }


        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }




#if WINDOWS


        public override EMessageResult HandleMessage(GMessage a_Msg)
        {
          
            return base.HandleMessage(a_Msg);
        }
#endif


        public override bool IsUseAble()
        {
            if (!IsSelectAble()) return false;

            IMouseInputHandler input = MouseInputHandler.GetInputHandler();

            if (input.IsOneClick())
            {
                GMessage message = new GMessage(MessageTypeID.MT_CHECK_ATTACK);
                //마우스 충돌이 일어난 엔티티들을 등록할 수 있다.
                message.m_Data = m_AttackInfo;

                m_ObjectMan.BroadCastMessage(message, ComponentTypeID.CID_MALARIA_ENTITY);

                if (m_MalariaList.Count > 0)
                {
                    m_bSelect = true;
                    return true;
                }

            }
            return false;
        }

        

        public override void Release()
        {
            base.Release();
        }

        public override bool IsStateEnd()
        {
            return false;
        }

        public override void UseItem(GameTime gameTime)
        {

            WebEffect effect = new WebEffect(new GObjectID(), m_ObjectMan, m_MalariaList[0] );
            m_ObjectMan.AddComponent(effect);

            CmpWeb cmpWeb = new CmpWeb(new GObjectID(), m_ObjectMan, m_MalariaList[0] , 2);
            m_ObjectMan.AddComponent(cmpWeb);

            m_MalariaList[0].StopMove();
            m_MalariaList.Clear();

        }

        public override bool IsSelectAble()
        {
            return m_bSelect;
        }
    }
}
